package com.frxuexi.mynews.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.frxuexi.mynews.R
import com.frxuexi.mynews.adapter.MyPagerAdapter
import com.frxuexi.mynews.databinding.ActivityMainBinding
import com.frxuexi.mynews.fragment.HomeFragment
import com.frxuexi.mynews.fragment.MeFragment
import com.frxuexi.mynews.fragment.SheFragment
import com.frxuexi.mynews.fragment.VideoFragment
import com.frxuexi.mynews.utils.MyViewPager

@Route(path = "/app/MainActivity")
class MainActivity : AppCompatActivity() {
    lateinit var db:ActivityMainBinding
    lateinit var vp: ViewPager
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        db=ActivityMainBinding.inflate(layoutInflater)
        setContentView(db.root)
        vp=db.mainVp

        val list = ArrayList<Fragment>()
        list.add(HomeFragment())
        list.add(VideoFragment())
        list.add(SheFragment())
        list.add(MeFragment())

        val adapter = MyPagerAdapter(
            supportFragmentManager,
            behivor = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,
            list
        )
        vp.adapter=adapter


        db.mainNav.setOnItemSelectedListener {
            if(it.itemId== R.id.item_home){
                vp.currentItem=0
            }else if(it.itemId== R.id.item_video){
                vp.currentItem=1
            }else if(it.itemId== R.id.item_she){
                vp.currentItem=2
            }else{
                vp.currentItem=3
            }
            return@setOnItemSelectedListener true
        }



    }
}